package com.ltu.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ltu.domain.mp_entity.UserEntity;
import com.ltu.model.response.reagent.CustomerCountDTO;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author 若尘
 * @since 2021-10-26
 */
public interface UserMapper extends BaseMapper<UserEntity> {
	
	@Select(value = " select u.* from sys_user u   ${ew.customSqlSegment}")
	Page<UserEntity>   customisePage (Page<UserEntity> page,@Param(Constants.WRAPPER) Wrapper<UserEntity>  wrapper);

	/**
	 * @Description: 近15天的用户数
	 * @author 李生
	 * @date 2024-10-25 12:25:42 
	 * @param beginDateTime
	 * @param endDateTime2
	 * @return
	 */
	@Select(value = " SELECT  count(*) as num , DATE_FORMAT(create_time,'%Y-%m-%d') as date FROM   sys_user WHERE create_time >= #{beginDateTime}   GROUP BY date; ")
	List<CustomerCountDTO> countUserBy15(@Param("beginDateTime") String beginDateTime);
	
	/**
	 * @Description: 近15天的订单数
	 * @author 李生
	 * @date 2024-10-25 12:25:42 
	 * @param beginDateTime
	 * @param endDateTime2
	 * @return
	 */
	@Select(value = " SELECT  count(*) as num , DATE_FORMAT(create_time,'%Y-%m-%d') as date FROM   sys_order  WHERE pay_status = 1 AND create_time >= #{beginDateTime}   GROUP BY date; ")
	List<CustomerCountDTO> countOrderBy15(@Param("beginDateTime") String beginDateTime);
	
	
	@Select(value = "SELECT store_name as date ,count(*) num  from sys_user  WHERE company_code = ${companyCode}  AND  store_name <> ''\r\n"
			+ "GROUP BY store_name\r\n"
			+ "ORDER BY num DESC")
	List<CustomerCountDTO> countByStoreUsers(@Param("companyCode")String companyCode);
	

	
	@Select(value = "SELECT store_name as date ,count(*) num  from sys_order  WHERE company_code = ${companyCode}  AND  store_name <> '' AND  pay_status =  1\r\n"
			+ "GROUP BY store_name\r\n"
			+ "ORDER BY num DESC ")
	List<CustomerCountDTO> countByStoreOrders(@Param("companyCode")String companyCode);
	

}
